package com.occludens.data.admin.util;

import static com.googlecode.objectify.ObjectifyService.ofy;

import java.util.List;

import com.google.common.base.Strings;
import com.occludens.admin.datamodel.User;

public class UserDAO extends AdminObjectDAO {
	
	public static User getUserByEmail(String email) {
		try {
			User returnUser = null;
			
			if (!Strings.isNullOrEmpty(email)) {
				List<User> users = ofy().load().type(User.class).filter("email", email).list();
				if (users!=null) {
					if (users.size()>1) {
						//then error, more than one person with same email
					} else {
						returnUser = users.get(0);
					}
				}
			}
			return returnUser;
		} catch (Exception e) {
			throw e;
		}
	}
	
	public static void delete(String email) {
		UserDAO.delete(UserDAO.getUserByEmail(email));
	}
	
	public static void delete(User user) {
		ofy().delete().entity(user);
	}
	
	public static void update() {
		//TODO to implement
	}


}
